package com.whxy02.tolearn.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.whxy02.tolearn.app.beans.Document;
import com.whxy02.tolearn.app.dao.DocumentDao;
import com.whxy02.tolearn.app.service.DocumentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class DocumentServiceImpl implements DocumentService {
    private QueryWrapper<Document> wrapper=new QueryWrapper<>();
    @Resource
    DocumentDao documentDao;

    @Override
    public List<Document> getAll() throws Exception {
        return documentDao.selectList(null);
    }

    @Override
    public Document getById(Integer id) throws Exception {
        return documentDao.selectById(id);
    }

    @Override
    public int save(Document document) throws Exception {
        return documentDao.insert(document);
    }

    @Override
    public int removeById(Integer id) throws Exception {
        return documentDao.deleteById(id);
    }

    @Override
    public int change(Document document) throws Exception {
        return documentDao.updateById(document);
    }

    @Override
    public List<Document> getByUserId(Integer id) throws Exception {
        wrapper.clear();
        wrapper.eq("user_id",id).orderByDesc("create_time");
        return documentDao.selectList(wrapper);
    }
}
